package com.young.shop_admin.controller;

import com.young.shop_admin.pojo.entity.Seller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/SellerLogin")
public class SellerLoginController extends BaseController {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //跨域
        resp.setHeader("Access-Control-Allow-Origin","http://localhost:63342");
        //获取输入信息
        Seller seller = convertParamsToEntity(req, Seller.class);
        //登入校验
        try {
            Seller dbSeller = sellerList.checkSellerLogin(seller);
            //用户信息存session
            req.getSession().setAttribute("seller", dbSeller);
            //返回登录信息
            writerSuccessResult(dbSeller, resp);

        } catch (RuntimeException e) {
            String errorMsg = e.getMessage();
            writerErrorResult(errorMsg, resp);
        }

    }
}
